package jwt.config;


import jwt.controller.LoginController;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;


public class MyTestProxy implements InvocationHandler {

    private Object proxyObject;

    public MyTestProxy(Object proxyObject) {
        this.proxyObject = proxyObject;
    }

    public static Object factory(Object obj){
        Class<?> aClass = obj.getClass();
        return Proxy.newProxyInstance(aClass.getClassLoader(),aClass.getInterfaces(),new MyTestProxy(obj));
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("before calling:"+method);
        if(args != null){
            for (Object arg : args) {
                System.out.println("args param:"+arg);
            }
        }
        Object invoke = method.invoke(proxyObject, args);

        System.out.println("after calling :"+ invoke);

        return invoke;
    }

    public static void main(String[] args) {
        List v =(List) factory(new Vector<>());
        v.add("这个");
        v.add("哪个");
    }
}
